package cn.restcloud.springboot.listener;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.stereotype.Component;
import cn.restcloud.framework.analysis.service.APIAccessAndExceptionLog;
import cn.restcloud.framework.core.util.LogUtil;
import cn.restcloud.framework.scheduler.service.SchedulerContext;


@Component
public class RestCloudDestory implements DisposableBean, ExitCodeGenerator {
	 
	    @Override
	    public void destroy() throws Exception {
	    	LogUtil.info("准备关闭系统.....");
	        SchedulerContext.shutdown(); //关闭定时任务处理程序
	        APIAccessAndExceptionLog.getApiAccessLogDao().saveLog(null, null);//关闭时把缓存的日志写入
	        
	        //关闭一些系统开启动的线程池
	        //ESBProcessEngineUtil.shutDown(true); //停止ESB中的线程池
	        //ServerConnectTestThreadUtil.shutDown(true); //链通性测试池程池关闭
	        //ETLThreadUtil.shutDown(true);//ETL异步并行执行路由线
	        //DirectlyWrite2FileImpl.shutDown(true);//写日志到文件线程
	        //DirectlyWrite2MongodbImpl.shutDown(true);//写日志到mongodb中
	        //TcpipPortConnectUtil.shutDown(true);//tcpip转发线程
	        
	    }
	 
	    @Override
	    public int getExitCode() {
	        return 5;
	    }
}
